package com.cbd.util;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cbd.pojo.Company;
import com.cbd.pojo.Landlady;
import com.cbd.pojo.Operator;
import com.cbd.pojo.Renter;

public class Filt implements Filter{

	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
			throws IOException, ServletException {
		// TODO Auto-generated method stub
		HttpServletRequest request = (HttpServletRequest) req;
		HttpServletResponse response = (HttpServletResponse) res;
		Landlady landlady =  (Landlady) request.getSession().getAttribute("myLandLady");   
		Operator operator =  (Operator) request.getSession().getAttribute("myOperator");   
		Company company =  (Company) request.getSession().getAttribute("myCompany");   
		Renter renter =  (Renter) request.getSession().getAttribute("myRenter");   
	        if( landlady == null && operator==null && company==null && renter==null){  
	           request.getRequestDispatcher("/login.jsp").forward(request, response);  
	            response.sendRedirect("/cbdproject/login.jsp");
	      
	        }else {
	        	chain.doFilter(request, response);
	        }
	}

	@Override
	public void init(FilterConfig arg0) throws ServletException {
		// TODO Auto-generated method stub
		
	}

}
